﻿@model ActivityLogSearchModel
@using Telerik.Web.Mvc;
@using Telerik.Web.Mvc.UI;
@{
    var gridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSize;
    
    //page title
    ViewBag.Title = T("Admin.Configuration.ActivityLog.ActivityLog").Text;
}
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            @T("Admin.Configuration.ActivityLog.ActivityLog")
        </div>
        <div class="options">
            <a href="@Url.Action("ClearAll")" class="t-button">@T("Admin.Common.Clear")</a>
        </div>
    </div>
    <p>
    </p>
    <table width="100%">
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.CreatedOnFrom):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.CreatedOnFrom)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.CreatedOnTo):
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.CreatedOnTo)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                @Html.NopLabelFor(model => model.ActivityLogTypeId):
            </td>
            <td class="adminData">
                @Html.DropDownList("ActivityLogTypeId", Model.ActivityLogType)
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="btnSearch" class="t-button" value="@T("Admin.Common.Search")" />
            </td>
        </tr>
    </table>    
    <table class="adminContent">
        <tr>
            <td>
                @(Html.Telerik().Grid<ActivityLogModel>()
                        .Name("activityLog-grid")
                        .DataKeys(x =>
                        {
                            x.Add(y => y.Id).RouteKey("Id");
                        })
                        .ClientEvents(events => events.OnDataBinding("onDataBinding"))
                        .Columns(columns =>
                        {
                            columns.Bound(x => x.ActivityLogTypeName)
                                .Centered();
                            columns.Bound(x => x.CustomerId)
                                .Template(x => Html.ActionLink(x.CustomerEmail, "Edit", "Customer", new { id = x.CustomerId }, new { }))
                                .ClientTemplate("<a href=\"" + @Url.Content("~/Admin/Customer/Edit/") + "<#= CustomerId #>\"><#= CustomerEmail #></a>");
                            columns.Bound(x => x.Comment)
                                .Centered();                        
                            columns.Bound(x => x.CreatedOn)
                                .Centered();
                            columns.Command(commands =>
                            {
                                commands.Delete().Text(T("Admin.Common.Delete").Text);
                            }).Title(T("Admin.Common.Delete").Text).Width(50);
                        })
                        .Pageable(settings => settings.PageSize(gridPageSize).Position(GridPagerPosition.Both))
                        .DataBinding(dataBinding =>
                        {
                            dataBinding.Ajax().Select("ListLogs", "ActivityLog")
                                .Delete("AcivityLogDelete", "ActivityLog");
                        })
                        .EnableCustomBinding(true))
            </td>
        </tr>
    </table>
    <script type="text/javascript">

        $(document).ready(function () {

            $('#btnSearch').click(function () {
                var grid = $('#activityLog-grid').data('tGrid');
                grid.currentPage = 1; //new search. Set page size to 1
                grid.ajaxRequest();
                return false;
            });
        });

        function onDataBinding(e) {
            var searchModel = {
                CreatedOnFrom: $('#@Html.FieldIdFor(model => model.CreatedOnFrom)').val(),
                CreatedOnTo: $('#@Html.FieldIdFor(model => model.CreatedOnTo)').val(),
                ActivityLogTypeId: $('#ActivityLogTypeId').val()
            };
            e.data = searchModel;
        }

   </script>    
}